package com.cy.pj.sys.web.pojo;

/**
 * @DATE: 2021/3/10 16:41
 * @Author: LuckyH
 */

// 基于此对象封装服务端响应到客户端数据 1、状态码 2、消息 3、数据。。。
public class JsonResult {
    // 状态码 1=ok
    private Integer state=1;

    // 状态信息
    private String message="ok";
    // 响应数据，一般为查询结果
    private Object data;

    public JsonResult(Integer state, String message) {
        this.state = state;
        this.message = message;
    }

    public JsonResult(Object data) {
        this.data = data;
    }

    public JsonResult(String message) {
        this.message = message;
    }

    public JsonResult(Integer state) {
        this.state = state;
    }

    public JsonResult(Throwable e){
//        this.state=0;
//        this.message=e.getMessage();
        this(0,e.getMessage());
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "JsonResult{" +
                "state=" + state +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
